//
//  LMRPDFTaskAlertViewCell.m
//  EditTabDemo
//
//  Created by lhy on 2021/4/1.
//  Copyright © 2021 lhy. All rights reserved.
//

#import "LMRPDFTaskAlertViewCell.h"
#define NUM @"0123456789"
#define ALPHANUM @"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"

@interface LMRPDFTaskAlertViewCell () <UITextFieldDelegate>

@end

@implementation LMRPDFTaskAlertViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    
    [self.ata1TextField becomeFirstResponder];
    
    self.ata1TextField.delegate = self;
    self.ata2TextField.delegate = self;
    self.ata3TextField.delegate = self;
    self.ata4TextField.delegate = self;
    self.ata5TextField.delegate = self;
    self.ata6TextField.delegate = self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}


#pragma mark ATA输入值判断
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    NSCharacterSet *cs = nil;
    NSString *filtered = nil;
    NSString *tostring= nil;
    cs=[[NSCharacterSet characterSetWithCharactersInString:NUM] invertedSet];
    filtered =[[string componentsSeparatedByCharactersInSet:cs] componentsJoinedByString:@""];
    if(textField.tag == 16){
        cs=[[NSCharacterSet characterSetWithCharactersInString:ALPHANUM] invertedSet];
        filtered =[[string componentsSeparatedByCharactersInSet:cs] componentsJoinedByString:@""];
     
    }
    switch (textField.tag) {
        case 11:
            tostring =[textField.text stringByReplacingCharactersInRange:range withString:string];
            if(tostring.length>2){
                _ata2TextField.text=@"";
                [_ata2TextField becomeFirstResponder];
            }
            break;
        case 12:
            tostring =[textField.text stringByReplacingCharactersInRange:range withString:string];
            if(tostring.length>2){
                _ata3TextField.text=@"";
                [_ata3TextField becomeFirstResponder];
            }
            break;
        case 13:
            tostring =[textField.text stringByReplacingCharactersInRange:range withString:string];
            if(tostring.length>2){
                _ata4TextField.text=@"";
                [_ata4TextField becomeFirstResponder];
            }

            break;
        case 14:
            tostring =[textField.text stringByReplacingCharactersInRange:range withString:string];
            if(tostring.length>3){
                _ata5TextField.text=@"";
                [_ata5TextField becomeFirstResponder];
            }
            textField.enabled = YES ;
            break;
        case 15:
            tostring =[textField.text stringByReplacingCharactersInRange:range withString:string];
            if(tostring.length>3){
                _ata6TextField.text=@"";
                [_ata6TextField becomeFirstResponder];
            }
            break;
        case 16:
            tostring =[textField.text stringByReplacingCharactersInRange:range withString:string];
            if(tostring.length>1){
                _ata6TextField.enabled = NO;
            }
            _ata6TextField.enabled =YES;
            break;
    }
    return [string isEqualToString:filtered];
}

@end
